home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: setupEndOfLog.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:55 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "volume.h"
- #include "openlog.h"
- #include "trans.h"
- #include "logrecs.h"
- #include "threadstate.h"
- #include "util_funcs.h"
- #include "log_intfuncs.h"
- #include "log_extfuncs.h"
- #include "recover_intfuncs.h"
- #include "recover_extfuncs.h"
- #include "trans_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "thread_funcs.h"
- #include "thread_globals.h"
- #include "log_globals.h"
-
-
- void
- setupEndOfLog (
-
- register LSNOFFSET lastLSN,
- BOOL formatPage
- )
- {
-
- GROUPLINK *tailLink;
- PAGEHASH *tailBuffer;
- LOGPAGEHDR *pageHeader;
- LOGPAGEHDR *endHeader;
- PID pid;
- OPENLOG *openLog;
- #ifdef DEBUG
- LSN debugLSN;
- #endif
-
-
- TRPRINT(TR_LOG|TR_RECOVER, TR_LEVEL_1, ("lastLSN:%d", lastLSN));
-
- /*
- * get a pointer to the openlog structure
- */
- openLog = &OpenLog;
-
- /*
- * setup the tail page of the log
- */
- openLog->tailPid = LSN_TO_LOG_PAGE(lastLSN, openLog);
- openLog->tailLSN = lastLSN;
- TRPRINT(TR_LOG|TR_RECOVER, TR_LEVEL_1, ("tailPid:%d", openLog->tailPid));
-
- /*
- * create the pid
- */
- pid.volid = openLog->volid;
- pid.page = LOG_PAGE_TO_BLOCK(openLog->tailPid, openLog);
-
- /*
- * read the new page
- */
- if ((tailLink = bf_ReadPage(openLog->writeGroup, &pid,
- openLog->page2size, BF_NOREAD)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * Unfix the page. The current page does not have to be fixed as
- * the semaphore on the log protects the currently active page. This
- * is an important assumption that will need to be maintained.
- */
- bf_UnfixPage(tailLink, BF_DEFAULT, FALSE);
-
- /*
- * record the pointer
- */
- tailBuffer = tailLink->pageHash;
-
- /*
- * mark that the buffer is a log buffer
- */
- PSET_PAGE_TYPE(tailBuffer, PAGE_LOG);
-
- /*
- * save the new buffer
- */
- openLog->tailBuffer = tailBuffer;
- openLog->tailLink = tailLink;
-
- /*
- * check to make sure the first mark and the force mark are zero
- */
- SM_ASSERT(LEVEL_3, ((tailBuffer->forceMark == 0) && (tailBuffer->firstMark == 0)));
-
- /*
- * get a pointer to the page header
- */
- pageHeader = (LOGPAGEHDR *) tailBuffer->bufFrame;
- endHeader = (LOGPAGEHDR *) (((char *) pageHeader) + openLog->lastUsableByte);
-
- /*
- * check the log page numbers
- */
- SM_ASSERT(LEVEL_1, pageHeader->pageNumber == openLog->tailPid);
- SM_ASSERT(LEVEL_1, endHeader->pageNumber == openLog->tailPid);
-
- /*
- * format the page if it is clean
- */
- if (formatPage) {
-
- TRPRINT(TR_LOG|TR_RECOVER, TR_LEVEL_2, ("formatting page"));
-
- #ifdef JUNK
- /*
- * check to see if the log has wrapped
- */
- if (openLog->tailPid == 0) {
-
- openLog->wrapCount++;
- }
- #endif JUNK
-
- /*
- * zero out the pge
- */
- bzero(tailBuffer->bufFrame, (int) openLog->pageSize);
-
- /*
- * initialize the header on the page
- */
- pageHeader->magic = LOGPAGE_MAGIC;
- pageHeader->wrapCount = openLog->wrapCount;
- pageHeader->lastRecord = NULL_LAST_RECORD;
- pageHeader->pageNumber = openLog->tailPid;
-
- /*
- * initialize the header on the page
- */
- endHeader->magic = LOGPAGE_MAGIC;
- endHeader->wrapCount = openLog->wrapCount;
- endHeader->lastRecord = NULL_LAST_RECORD;
- endHeader->pageNumber = openLog->tailPid;
-
- /*
- * dirty the page
- */
- #ifdef DEBUG
- waitSemaphore(&(tailBuffer->semaphore));
- #endif
- DIRTY_PAGE(tailBuffer);
- #ifdef DEBUG
- signalSemaphore(&(tailBuffer->semaphore));
- #endif
- #ifdef DEBUG
- /* make sure we don't overwrite important log records */
- debugLSN.offset = openLog->tailLSN;
- debugLSN.wrapCount = openLog->wrapCount;
- debugLSN.wrapCount--;
- if(compareLSN(&debugLSN, &OldestDirtyPageLSN) >= 0) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
- #endif
- }
- }
-